import { Controller, Get, Post } from "@nestjs/common";
import { ApiBearerAuth, ApiOperation, ApiTags } from "@nestjs/swagger";
import { MiniappService } from "./miniapp.service";
import { UserService } from "../user/user.service";
import { AuthUser } from "../auth/decorators/auth-user.decorator";
import { ModuleSwaggerTags } from "~/constants/modules.constant";
import { AllowAnon } from "../auth/decorators/allow-anon.decorator";
import { TenantService } from "../tenant/tenant.service";
import { AuthTenant } from "../tenant/tenant.decorator";
import { ApiTenantHeader } from "~/common/decorators/api-header-tenant.decorator";
import { CategoryDiseaseService } from "../category-disease/category-disease.service";

@ApiBearerAuth()
@Controller()
export class MiniappController {

	constructor(
		private readonly miniappService: MiniappService,
		private readonly userService: UserService,
		private readonly tenantService: TenantService,
		private readonly categoryDiseaseService: CategoryDiseaseService, // 假设有这个服务
	) {}

	// 获取当前用户的信息
	@ApiTags(ModuleSwaggerTags.USER)
	@Get('user')
	@AllowAnon()
	@ApiOperation({ summary: '获取当前用户信息' })
	async getUserInfo(@AuthUser() user: IAuthUser) {
		const diseaseId = await this.categoryDiseaseService.findCategoryIdByUserId(user?.uid);
		const userInfo = await this.userService.getAccountInfo(user?.uid);

		return {
			...userInfo,
			diseaseId: diseaseId ?? null, // 如果没有关联的疾病类别ID，则返回null
		}
	}

	@ApiTags(ModuleSwaggerTags.TENANT)
	@Get('tenant')
	@AllowAnon()
	@ApiTenantHeader()
	@ApiOperation({ summary: '获取当前租户信息' })
	async getTenantInfo(@AuthTenant() tenant: IAuthTenant) {
		return await this.tenantService.getTenantById(tenant.id);
	}

	// 关于我们
	@ApiTags('Common - 小程序模块')
	@Get('about')
	@ApiOperation({ summary: '关于我们 - 待完成' })
	async getAbout() {
		// TODO 获取关于我们
	}

	// 联系我们
	@ApiTags('Common - 小程序模块')
	@Post('contact')
	@ApiOperation({ summary: '联系我们 - 待完成' })
	async getContact() {
		// TODO 获取联系我们
	}
}